/*******************************************************************************
 * Copyright (c) 2011 Erik Byström.
 * 
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program. If
 * not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package tazadum.engine.math;

import java.util.Comparator;

/**
 * @author Erik Byström
 * 
 */
public class Vectors {
	private Vectors() {
		// don't instantiate
	}

	/**
	 * Calculate the dot product between two vectors.
	 * 
	 * @param a
	 * @param b
	 * @return
	 */
	public static float dot(final Vector a, final Vector b) {
		return a.x * b.x + a.y * b.y + a.z * b.z;
	}

	/**
	 * Calculates the cross product between two vector and returns it as a new vector.
	 * 
	 * @param a
	 * @param b
	 * @return
	 */
	public static Vector cross(final Vector a, final Vector b) {
		return new Vector(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.z);
	}

	/**
	 * Subtract a vector from another and return the result as a new vector.
	 * 
	 * @param a
	 * @param b
	 * @return
	 */
	public static Vector sub(final Vector a, final Vector b) {
		return new Vector(a.x - b.x, a.y - b.y, a.z - b.z);
	}

	/**
	 * Compare Vectors by the z-component, ascending.
	 */
	public static Comparator<Vector> SORT_BY_Z = new Comparator<Vector>() {
		@Override
		public int compare(final Vector o1, final Vector o2) {
			return Float.compare(o1.z, o2.z);
		}
	};
}
